import Vue from 'vue'
import VueRouter from 'vue-router'

const User = () =>
    import ('../components/User')
const Home = () =>
    import ('../components/Home')
    // 路由赖加载
const About = () =>
    import ('../components/About')
const HomeNews = () =>
    import ('../components/HomeNews')
const HomeMessage = () =>
    import ('../components/HomeMessage')
const Profile = () =>
    import ('../components/Profile')
    //通过Vue.use(插件),安装
Vue.use(VueRouter)
const routes = [{
            path: '',
            //redirect重定向,默认路径
            redirect: '/home'
        },
        {
            path: '/home',
            component: Home,
            meta: {
                title: '首页'
            },
            children: [{
                    path: '',
                    redirect: 'news'
                },
                {
                    path: 'news',
                    component: HomeNews
                },
                {
                    path: 'message',
                    component: HomeMessage
                },
            ]
        },

        {
            path: '/about',
            component: About,
            meta: {
                title: '关于'
            }
        },
        {
            path: '/user/:id',
            component: User,
            meta: {
                title: '用户'
            }
        },
        {
            path: '/profile',
            component: Profile,
            meta: {
                title: '档案'
            }
        }
    ]
    //创建路由对象
const router = new VueRouter({

        routes,
        mode: 'history'

    })
    // 路由导航对象
router.beforeEach((to, from, next) => {
    document.title = to.matched[0].meta.title
    next()

})

3. //将router 对象传入到Vue实例
export default router